﻿using System;
using Newtonsoft.Json;

namespace CkSoftware.GroupMe.Sdk.Groups.Dao
{
	/// <summary>
	/// The DAO which is used to add a new member to a group.
	/// </summary>
	public class AddMemberData
	{
		private readonly Guid _addMemberId;

		/// <summary>
		/// Instantiate a new <see cref="AddMemberData" />.
		/// </summary>
		public AddMemberData()
		{
			_addMemberId = Guid.NewGuid();
		}

		/// <summary>
		/// The email of the member to add.
		/// </summary>
		[JsonProperty(PropertyName = "email")]
		public string Email { get; set; }

		/// <summary>
		/// The own user guid used to identify the added user after the async processing is finished.
		/// </summary>
		[JsonProperty(PropertyName = "guid")]
		public Guid Guid
		{
			get { return _addMemberId; }
		}

		/// <summary>
		/// The nickname of the member to add.
		/// </summary>
		[JsonProperty(PropertyName = "nickname")]
		public string Nickname { get; set; }

		/// <summary>
		/// The phone number of the member to add.
		/// </summary>
		[JsonProperty(PropertyName = "phone_number")]
		public string PhoneNumber { get; set; }

		/// <summary>
		/// The user id of the member to add.
		/// </summary>
		[JsonProperty(PropertyName = "user_id")]
		public string UserId { get; set; }

		/// <summary>
		/// Validates if the current user-definition is valid for an add operation.
		/// </summary>
		/// <returns>True if the data is valid, otherwise false.</returns>
		public bool IsValid()
		{
			return Guid != Guid.Empty && !string.IsNullOrEmpty(Nickname) &&
			       (!string.IsNullOrEmpty(UserId) || !string.IsNullOrEmpty(PhoneNumber) || !string.IsNullOrEmpty(Email));
		}
	}
}